<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/3/10-14:17
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->


{extend name='public/base' /}


{block name="css"}
<link href="__PLUGS__/layui/lay/hhymodel/openTable/openTable.css?v=1.0" rel="stylesheet">

<style type="text/css">
    .layui-table img{
        max-width:200px;
        max-height: 80px;
    }
</style>
{/block}
{block name="content"}

<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-body layui-row ">

            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">

                    <div class="layui-inline">
                        <label class="layui-form-label">所属栏目：</label>
                        <div class="layui-input-inline">
                            {:widget('common/forms/singleSelect',array('category_id|2|所属分类|title_show|id',$tree,0))}
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">相册搜索：</label>
                        <div class="layui-input-inline">
                            <input name="title" class="layui-input" value="" type="text" placeholder="请输入标题">
                        </div>
                    </div>

                    <div class="layui-inline" style="padding-left: 20px;">
                        <button class="layui-btn icon-btn layui-btn-sm" lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" onclick="javascript:window.location.reload();">
                            <i class="layui-icon layui-icon-refresh"></i> 重置
                        </button>
                    </div>

                </div>

            </form>

        </div>

    </div>


    <div class="layui-card">
        <div class="layui-card-header" style="line-height: 55px;">
            <div class="layui-btn-container do_btn">
                <!--按钮区-->
                <button class="layui-btn layui-btn-sm" data-type="add"><i class="layui-icon"></i>新增相册</button>
                <button class="layui-btn layui-btn-danger layui-btn-sm" onmouseover="tis(this)" data-title="删除相册" data-type="del"><i class="layui-icon "></i>删除</button>
                <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="reload"><i class="fa fa-refresh"></i> 刷新</button>
                <button class="layui-btn layui-btn-sm layui-btn-warm" data-type="move">移动相册</button>

                <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="up"><i class="layui-icon layui-icon-upload"></i>上传相册图片</button>

            </div>
        </div>
        <div class="layui-card-body">

            <!--表格区-->

            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>


{/block}


{block name="js"} <!--js处理区-->


<!--模板-->
<script type="text/html" id="operationTpl">

    {:widget('common/forms/Editbtn',array('编辑相册信息'))}
    <a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-xs " onmouseover="tis(this)" data-title="查看相册图片" lay-event="view">
        <i class="layui-icon layui-icon-tree"></i>
    </a>
    {:widget('common/forms/Delbtn',array('删除文章',2))}

</script>

<script type="text/html" id="is_show">
    <input type="checkbox" name="is_show"  lay-data="{{d.is_show}}" value="{{d.id}}"  lay-filter="is_show" lay-skin="switch"  lay-text="显示|不显示"  {{ d.is_show == 1 ? 'checked' : '' }}>
</script>


<script type="text/html" id="is_top">
    <input type="checkbox" name="is_top"  lay-data="{{d.is_top}}" value="{{d.id}}"  lay-filter="is_top" lay-skin="switch"  lay-text="置顶|不置顶"  {{ d.is_top == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="is_open">
    <input type="checkbox" name="is_open"  lay-data="{{d.is_open}}" value="{{d.id}}"  lay-filter="is_open" lay-skin="switch"  lay-text="加密|不加密"  {{ d.is_open == 1 ? 'checked' : '' }}>
</script>

<script>

    layui.use(['element', 'table', 'form', 'jquery', 'lucky','openTable'], function () {
        let element = layui.element;
        let form = layui.form;
        let table = layui.table;
        let $ = layui.jquery;
        let lucky=layui.lucky;
        let openTable=layui.openTable;

        form.render();

        // layer.load(2);
        openTable.render({
            elem: '#tableFilter',
            url:"{:url('album/index')}",
            //toolbar: '#toolbarDemo',
            // even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[20,30,50,60]
            },
            // height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                {field: 'img', title: '相册封面', style:'cursor: pointer;',width: 150, align: "center",templet:function (d) {
                        return '<img src="'+d.img+'"  layer-index="0" alt="无图" style="height:40px;" />';
                    }},
                {field: 'name', minWidth: 130, title: '相册名称',templet:function (d) {
                        return '<font  onmouseover="tis(this)" color="red" data-title="'+d.name+'">'+d.name+'</font>'
                    }},
                {field: 'cname',style:'cursor: pointer;',title: '所属栏目',width:150},
                {field: 'describe', title: '相册描述', width: 150, style:'cursor: pointer;', templet:function (d) {
                        return '<font  onmouseover="tis(this)" data-title="'+d.describe+'">'+d.describe+'</font>'
                    }},
                {field:'is_show',title:'是否显示',templet: '#is_show',width:110 ,unresize: true},
                {field: 'nums',style:'cursor: pointer;',title: '相片数',width:90,sort:true},
                {field:'is_top',title:'是否置顶',templet: '#is_top',width:110 ,unresize: true},
                {field:'is_open',title:'是否加密',templet: '#is_open',width:110 ,unresize: true},
                {field: 'create_time', title: '添加时间',align: 'center',width:160,sort:true},
                {fixed: 'right',templet: '#operationTpl', width: 110, align: 'center', title: '操作'}
            ]],
            //注：展开的列Items
            openCols: [
                //  1、普通文本
                {field: 'tags', title: '标签'},
                {field: 'password', title: '加密密码'},
                {field: 'hits', title: '浏览数'},
                {field: 'ip', title: 'ip地址'},
                //	4、可选择的类型 select
            ]
            //注：监听排序 {openTable}
            ,sort: function (obj) {
                console.log(obj)
            }
            //注：监听修改 {openTable}
            ,edit: function (obj) {
                //layer.msg("修改内容已打印在控制台");
                console.log(obj)
                // 发起 ajax
                // layui.table.reload('#test');
            }

            //注：0：同时只展开一项 1：一直展开不关闭之前  def：0 {openTable}
            , openType: 0
            ,done: function (res) {
                layer.closeAll('loading');
                hoverOpenImg();
            }
        });



        /**
         * 鼠标悬浮显示大图
         *
         */
        function hoverOpenImg(){
            let img_show = null; // tips提示
            $('td img').hover(function(){
                let img = "<img class='img_msg' src='"+$(this).attr('src')+"' style='width:100%;' />";
                img_show = layer.tips(img, this,{
                    tips:[2, 'rgba(41,41,41,.0)']
                    ,area: ['12%']
                });
            },function(){
                layer.close(img_show);
            });
        }


        form.on('switch(is_show)', function(obj){
            let _id=parseInt(obj.value);
            let pan=obj.elem.checked;
            let status;
            if (pan===false){
                status=0;
            }else {
                status=1;
            }
            lucky.Change_status("{:url('common/changeStatus')}","tableFilter","album",_id,"is_show",status, obj.othis);
        });


        form.on('switch(is_top)', function(obj){
            let _id=parseInt(obj.value);
            let pan=obj.elem.checked;
            let status;
            if (pan===false){
                status=0;
            }else {
                status=1;
            }
            lucky.Change_status("{:url('common/changeStatus')}","tableFilter","album",_id,"is_top",status, obj.othis);
        });


        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch("table_id",obj.field); //查询
            return false;
        });











        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            let data = obj.data;
            // console.log(JSON.stringify(data));
            let _id=parseInt(data.id);
            let layEvent = obj.event;
            if(layEvent==="edit"){

                let urls="/admin/album/editAlbum/id/"+_id;
                lucky.CreateForm("编辑相册信息",'60%','75%',urls,"table_id",0);

            }else if(layEvent==="del"){
                lucky.Delete_data(_id,"{:url('album/del')}","table_id");

            }else if (layEvent==="view"){
                let open=parseInt(data.is_open);
                let urls="/admin/album/viewImages/id/"+_id;

                if (open==0){
                    lucky.CreateForm("查看相册图片",'60%','75%',urls,"table_id",0);
                } else {
                    //加密
                    layer.prompt({
                        btn: ['确定'],
                        title: '请输入相册密码！',
                        closeBtn: 1,
                        formType: 1,
                        shade: 0.5,
                    }, function (value, index) {
                        $.post("{:url('album/passLock')}",{password:value,id:id},function (res) {
                            if (res.code==1){
                                layer.close(index);
                                layer.msg(res.msg,{icon: 1, time: 1500,shade:0.3, anim: 4},function () {
                                    lucky.CreateForm("查看相册图片",'60%','75%',urls,"table_id",0);
                                });
                            }else {
                                layer.msg(res.msg, {anim: 6,time:1500});
                                return false;
                            }
                        });
                    });
                }
            }
        });


        let active = {
            add:function(){
                lucky.CreateForm("添加相册",'60%','75%',"{:url('album/addAlbum')}","table_id",0);
            },
            del: function(){ //获取选中数据
                let checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                let num=0;
                let id=[];
                for (let i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.Delete_data(id,"{:url('album/del')}","table_id");
            },
            reload: function(){
                lucky.CreateReload("table_id");
            },
            up:function(){
                lucky.CreateForm("添加相册图片",'60%','75%',"{:url('album/addImages')}","table_id",0);
            },
            move:function () {
                let checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                let num=0;
                let id=[];
                for (let i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                $.post('{:url("category/moveSelect")}',{ids:id},function(data){
                    layer.open({
                        type: 1,
                        title: '数据移动',
                        area: ['auto', '490px'],
                        content: data //这里content是一个普通的String
                    });
                    form.render('select');//刷新重新加载select

                    form.on('select(category_id)', function(data){
                        //  param.to_category_id = data.value;
                        let selected_text = $(data.elem).find("option:selected").text();
                        //确认移动
                        layer.confirm('确定批量移动至【'+selected_text+'】?', function(index){
                            $.post('{:url("album/removeCategory")}',{ids:id,category_id:data.value},function(data){
                                if(data.code == 1){

                                    layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                                        location.reload();//do something
                                    });
                                }else{
                                    layer.msg(data.msg, {icon: 2,anim: 6, time: 1000});
                                }
                            }).error(function () {
                                layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
                            });
                        });
                    });
                }).error(function () {
                    layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
                });

                return false;


            }
        };

        $('.do_btn .layui-btn').on('click', function(){
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >


{/block}
